home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / ab20 / unarced / graphics / anim / unpacker.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  2KB  |  61 lines

  1. /*----------------------------------------------------------------------*
  2.  * unpacker.c Convert data from "cmpByteRun1" run compression. 11/15/85
  3.  *
  4.  * By Jerry Morrison and Steve Shaw, Electronic Arts.
  5.  * This software is in the public domain.
  6.  *
  7.  *    control bytes:
  8.  *     [0..127]   : followed by n+1 bytes of data.
  9.  *     [-1..-127] : followed by byte to be repeated (-n)+1 times.
  10.  *     -128       : NOOP.
  11.  *
  12.  * This version for the Commodore-Amiga computer.
  13.  *----------------------------------------------------------------------*/
  14. #include "functions.h"
  15. #include "packer.h"
  16.  
  17.  
  18. /*----------- UnPackRow ------------------------------------------------*/
  19.  
  20. #define UGetByte()    (*source++)
  21. #define UPutByte(c)    (*dest++ = (c))
  22.  
  23. /* Given POINTERS to POINTER variables, unpacks one row, updating the source
  24.  * and destination pointers until it produces dstBytes bytes. */
  25. BOOL UnPackRow(pSource, pDest, srcBytes0, dstBytes0)
  26.     BYTE **pSource, **pDest;  WORD srcBytes0, dstBytes0; {
  27.     register BYTE *source = *pSource;
  28.     register BYTE *dest   = *pDest;
  29.     register WORD n;
  30.     register BYTE c;
  31.     register WORD srcBytes = srcBytes0, dstBytes = dstBytes0;
  32.     BOOL error = TRUE;    /* assume error until we make it through the loop */
  33.     WORD minus128 = -128;  /* get the compiler to generate a CMP.W */
  34.  
  35.     while( dstBytes > 0 )  {
  36.     if ( (srcBytes -= 1) < 0 )  goto ErrorExit;
  37.         n = UGetByte();
  38.  
  39.         if (n >= 0) {
  40.         n += 1;
  41.         if ( (srcBytes -= n) < 0 )  goto ErrorExit;
  42.         if ( (dstBytes -= n) < 0 )  goto ErrorExit;
  43.         do {  UPutByte(UGetByte());  } while (--n > 0);
  44.         }
  45.  
  46.         else if (n != minus128) {
  47.         n = -n + 1;
  48.         if ( (srcBytes -= 1) < 0 )  goto ErrorExit;
  49.         if ( (dstBytes -= n) < 0 )  goto ErrorExit;
  50.         c = UGetByte();
  51.         do {  UPutByte(c);  } while (--n > 0);
  52.         }
  53.     }
  54.     error = FALSE;    /* success! */
  55.  
  56.   ErrorExit:
  57.     *pSource = source;  *pDest = dest;
  58.     return(error);
  59.     }
  60.  
  61.